<template>
  <div element-loading-text="模型生成中...">
    <div style="width: 280px; border: 1px solid white; ">
      <el-form  ref="form" label-width="80px">
        <div class="selectItem">
          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>
          <div class="selectTitle" >
           one基准面
          </div>
          <div class="selectedItem" v-if="oneSide">
            <span>{{oneSide.name}}</span>
            <span @click="removeOne">×</span>
          </div>
        </div>
        <el-form-item label="偏移距离">
          <el-input size="small" v-model.number="oneD" type="number" placeholder="请输入内容">
            <div slot="append">
              <el-button @click="changeDirectionOne">移动</el-button>
            </div>
            <i slot="suffix" style="font-style:normal; color: #606266;margin-right: 5px">mm</i>
          </el-input>
        </el-form-item>
        <div class="selectItem">
          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>
          <div class="selectTitle" >
            two基准面
          </div>
          <div class="selectedItem" v-if="twoSide">
            <span>{{twoSide.name}}</span>
            <span @click="removeTwo">×</span>
          </div>
        </div>
        <el-form-item label="偏移距离">
          <el-input size="small" v-model.number="twoD" type="number" placeholder="请输入内容">
            <div slot="append">
              <el-button  @click="changeDirectionTwo">移动</el-button>
            </div>
            <i slot="suffix" style="font-style:normal; color: #606266;margin-right: 5px">mm</i>
          </el-input>
        </el-form-item>
        <div class="selectItem">
          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>
          <div class="selectTitle" >
            three基准面
          </div>
          <div class="selectedItem" v-if="threeSide">
            <span>{{threeSide.name}}</span>
            <span @click="removeThree">×</span>
          </div>
        </div>
        <el-form-item label="偏移距离">
          <el-input size="small" v-model.number="threeD" type="number" placeholder="请输入内容">
            <div slot="append">
              <el-button  @click="changeDirectionThree">移动</el-button>
            </div>
            <i slot="suffix" style="font-style:normal; color: #606266;margin-right: 5px">mm</i>
          </el-input>
        </el-form-item>
        <div class="selectItem">
          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>
          <div class="selectTitle" >
            four基准面
          </div>
          <div class="selectedItem" v-if="fourSide">
            <span>{{fourSide.name}}</span>
            <span @click="removeFour">×</span>
          </div>
        </div>
        <el-form-item label="偏移距离">
          <el-input size="small" v-model.number="fourD" type="number" placeholder="请输入内容">
            <div slot="append">
              <el-button @click="changeDirectionFour">移动</el-button>
            </div>
            <i slot="suffix" style="font-style:normal; color: #606266;margin-right: 5px">mm</i>
          </el-input>
        </el-form-item>
        <div style="margin-top: 10px;text-align: center;">
          <el-button type="primary" size="small" @click="creatSkinTool" >确定</el-button>
          <el-button size="small"  @click="closeDialog">关闭</el-button>
        </div>
<!--        <div class="selectItem">-->
<!--          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>-->
<!--          <div class="selectTitle" >-->
<!--            <el-radio v-model="radio" label="1">曲面0裁剪线</el-radio>-->
<!--          </div>-->
<!--          <div class="selectedItem"  v-for="(item, index) in lines1" :key="index">-->
<!--            <span>{{item.name}}</span>-->
<!--            <span @click="removeLine(index)">×</span>-->
<!--          </div>-->
<!--        </div>-->

<!--        <div class="selectItem">-->
<!--          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>-->
<!--          <div class="selectTitle" >-->
<!--            <el-radio v-model="radio" label="2">曲面1裁剪线</el-radio>-->
<!--          </div>-->
<!--          <div class="selectedItem"  v-for="(item, index) in lines2" :key="index">-->
<!--            <span>{{item.name}}</span>-->
<!--            <span @click="removeLine(index)">×</span>-->
<!--          </div>-->
<!--        </div>-->

<!--        <div class="selectItem">-->
<!--          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>-->
<!--          <div class="selectTitle" >-->
<!--            <el-radio v-model="radio" label="3">曲面2裁剪线</el-radio>-->
<!--          </div>-->
<!--          <div class="selectedItem"  v-for="(item, index) in lines3" :key="index">-->
<!--            <span>{{item.name}}</span>-->
<!--            <span @click="removeLine(index)">×</span>-->
<!--          </div>-->
<!--        </div>-->

<!--        <div class="selectItem">-->
<!--          <div class="color-bar" style="background-color: rgb(192, 20, 255);"></div>-->
<!--          <div class="selectTitle" >-->
<!--            <el-radio v-model="radio" label="4">曲面3裁剪线</el-radio>-->
<!--          </div>-->
<!--          <div class="selectedItem"  v-for="(item, index) in lines4" :key="index">-->
<!--            <span>{{item.name}}</span>-->
<!--            <span @click="removeLine(index)">×</span>-->
<!--          </div>-->
<!--        </div>-->
      </el-form>
<!--      <div>-->
<!--        <div style="margin-top: 10px;text-align: center;">-->
<!--          <el-button type="primary" size="small" @click="calSurfaces">裁剪多余曲面</el-button>-->
<!--          <el-button size="small"  @click="closeSplineDialog">取消</el-button>-->
<!--        </div>-->
<!--      </div>-->
    </div>
  </div>
</template>

<script>
  import {
    Axis,
    CrownCADPlugin,
    Direction,
    PluginFunctionType,
    Point,
    PluginEventType,
    PluginCADToolFunctionType
  } from "../../../../nodeApp/static/lib/crowncad-plugin-sdk-0.0.1";
  export default {
    name: "ThreadedRod",
    data() {
      return {
        loading: false,
        type: '1',
        p: 2,   // 螺距
        oneSide: null,
        oneName: 'one',
        oneD:0,
        oneId:0,
        twoSide: null,
        twoName: 'two',
        twoD:0,
        twoId:0,
        threeSide: null,
        threeName: 'three',
        threeD:0,
        threeId:0,
        fourSide: null,
        fourName: 'four',
        fourD:0,
        fourId:0,
        basicPlane: null,
        sketchInfo: null,
        solidInfo: null,
        basicD: 0,
        basicD1: 0,
        h:0,
        surfaces:[],
        faces:[],
        radio: 0,
        lines1:[],
        lines2:[],
        lines3:[],
        lines4:[]
      }
    },
    async mounted() {
      //创建插件对象
      this.crownCADPlugin = new CrownCADPlugin();
      //设置CrownCAD平台地址
      this.crownCADPlugin.setParentOrigin(window.url);
      //.设置与CrownCAD平台尝试建立连接的次数
      this.crownCADPlugin.setMaxAttempt(5);
      //设置插件在CrownCAD平台显示的尺寸
      this.crownCADPlugin.setLayout(300, 300, 400);

      //.发送与CrownCAD平台建立连接的请求
      await this.crownCADPlugin.connect()

      await this.crownCADPlugin.request.execFunction(PluginFunctionType.LAYOUT, { minWidth: 300, width: 300, maxHeight: 375})

      this.subscribeElementPick()
      this.crownCADPlugin.command.clearCommand();
      await this.getAll()
    },
    methods: {
      //关闭对话框
      closeDialog() {
        this.crownCADPlugin.request.execFunction(PluginCADToolFunctionType.CLOSEACTIVECMD, null);
      },

      // 增加对话框高度
      async addHeight() {
        this.minHeight= this.minHeight + 28
        await this.crownCADPlugin.request.execFunction(PluginFunctionType.LAYOUT, { minWidth: 300, width: 300, maxHeight: this.minHeight})
      },

      // 减少对话框高度
      async minusHeight() {
        this.minHeight= this.minHeight - 28
        await this.crownCADPlugin.request.execFunction(PluginFunctionType.LAYOUT, { minWidth: 300, width: 300, maxHeight: this.minHeight})
      },

      async creatSkinTool() {
        this.loading = true
        //清空command
        this.crownCADPlugin.command.clearCommand();

        let oneId= await this.getBasciPlaneId(this.oneName)

        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图3', datumId: oneId});
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*2-this.fourD -this.basicD1, 0, 0),
          endPoint:new Point(this.basicD1*2-this.fourD -this.basicD1, this.h+20, 0)
        })

        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(this.basicD1*-1+this.fourD, 0, 0),
        //   endPoint:new Point(this.basicD1*-1+this.fourD, this.h+20, 0)
        // })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*2-this.fourD -this.basicD1, this.h+20, 0),
          endPoint:new Point(this.basicD1*-2-this.threeD+this.basicD1, this.h+20, 0)
        })

        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(this.basicD1*-1+this.fourD, this.h+20, 0),
        //   endPoint:new Point(this.basicD1+this.threeD, this.h+20, 0)
        // })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*-2-this.threeD+this.basicD1, this.h+20, 0),
          endPoint:new Point(this.basicD1*-2-this.threeD+this.basicD1, 0, 0)
        })


        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(this.basicD1+this.threeD, this.h+20, 0),
        //   endPoint:new Point(this.basicD1+this.threeD, 0, 0)
        // })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*-2-this.threeD+this.basicD1, 0, 0),
          endPoint:new Point(this.basicD1*2-this.fourD -this.basicD1, 0, 0)
        })

        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(this.basicD1+this.threeD, 0, 0),
        //   endPoint:new Point(this.basicD1*-1+this.fourD, 0, 0)
        // })


        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();

        let res= await this.crownCADPlugin.query.getEntitiesByFeatureNames(["草图3"])

        let ids= []
        ids.push(res.data.entities[0]?.id)



        let twoId= await this.getBasciPlaneId(this.twoName)

        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图4', datumId: twoId});
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*2-this.fourD -this.basicD1, 0, 0),
          endPoint:new Point(this.basicD1*2-this.fourD -this.basicD1, this.h+20, 0)
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*2-this.fourD -this.basicD1, this.h+20, 0),
          endPoint:new Point(this.basicD1*-2-this.threeD+this.basicD1, this.h+20, 0)
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*-2-this.threeD+this.basicD1, this.h+20, 0),
          endPoint:new Point(this.basicD1*-2-this.threeD+this.basicD1, 0, 0)
        })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD1*-2-this.threeD+this.basicD1, 0, 0),
          endPoint:new Point(this.basicD1*2-this.fourD -this.basicD1, 0, 0)
        })

        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();

        let res1= await this.crownCADPlugin.query.getEntitiesByFeatureNames(["草图4"])

        ids.push(res1.data.entities[0]?.id)


        let threeId= await this.getBasciPlaneId(this.threeName)

        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图5', datumId: threeId});
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD-(this.basicD*2 - this.twoD), 0, 0),
          endPoint:new Point(this.basicD-(this.basicD*2 - this.twoD), this.h+20, 0)
        })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD-(this.basicD*2 - this.twoD), this.h+20, 0),
          endPoint:new Point(this.basicD*2 + this.oneD- this.basicD, this.h+20, 0)
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD*2 + this.oneD- this.basicD, this.h+20, 0),
          endPoint:new Point(this.basicD*2 + this.oneD- this.basicD, 0, 0)
        })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD*2 + this.oneD- this.basicD, 0, 0),
          endPoint:new Point(this.basicD-(this.basicD*2 - this.twoD), 0, 0)
        })

        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();


        let res2= await this.crownCADPlugin.query.getEntitiesByFeatureNames(["草图5"])

        ids.push(res2.data.entities[0]?.id)

        let fourId= await this.getBasciPlaneId(this.fourName)

        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图6', datumId: fourId});
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD*2+ this.oneD -this.basicD, 0, 0),
          endPoint:new Point(this.basicD*2+ this.oneD -this.basicD, this.h+20, 0)
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD*2+ this.oneD -this.basicD, this.h+20, 0),
          endPoint:new Point(this.basicD -(this.basicD*2-this.twoD), this.h+20, 0)
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD -(this.basicD*2-this.twoD), this.h+20, 0),
          endPoint:new Point(this.basicD -(this.basicD*2-this.twoD), 0, 0)
        })

        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(this.basicD -(this.basicD*2-this.twoD), 0, 0),
          endPoint:new Point(this.basicD*2+ this.oneD -this.basicD, 0, 0)
        })

        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();
        let res3= await this.crownCADPlugin.query.getEntitiesByFeatureNames(['草图6'])


        ids.push(res3.data.entities[0]?.id)

        for (let i = 0; i < ids.length; i++) {
          await this.createPlaneSurface(ids[i], '填充曲面'+ i)
        }

        await this.getAll1()

        let limitIds= []
        let surfaceIds= []
        this.surfaces.forEach(surface => {
          limitIds.push(surface.id)
        })

        surfaceIds.push(this.faces[0].id)
        surfaceIds.push(this.faces[1].id)

        let oldSurfaceIds= [this.faces[0].id,this.faces[0].id, this.faces[1].id,this.faces[1].id]

        await this.trimSurfaces(limitIds,surfaceIds, 1,[1,0,1,0], oldSurfaceIds,[0,0,0,0],'裁剪曲面')

        // for (let i = 0; i < limitIds.length; i++) {
        //
        // }

        await this.setEntityVisible(limitIds)
        // await this.getAll2()
      },


      async getAll() {
        this.crownCADPlugin.command.clearCommand();
        let sketch= 0
        let solid= 0
        let res= await this.crownCADPlugin.query.getEntities()

        res.data.entities.forEach(entity => {
          if(entity.type=== 6) {

            sketch= entity.featureId
          } else if(entity.type=== 4) {
            solid= entity
          }
        })


         this.sketchInfo = await this.crownCADPlugin.query.getElementsByFeatureId(sketch);

         if(!this.oneId) {
           this.oneId= await this.createBasicPlane1(22,this.sketchInfo.data.elements[0].params.startPoint[0],'one')
           this.basicD= Math.abs(this.sketchInfo.data.elements[0].params.startPoint[0].toFixed(2))

         }
         if(!this.twoId) {
           this.twoId= await this.createBasicPlane1(22,this.sketchInfo.data.elements[0].params.startPoint[0]*-1,'two')
           // this.twoD= (this.sketchInfo.elements[0].params.startPoint[0]*-1).toFixed(2)
         }

         this.solidInfo = await this.crownCADPlugin.query.getElementsByEntityId(solid.id);


        let solidInfo= []

          this.solidInfo.data.elements.forEach(element => {
            if(element.type=== 20) {
              solidInfo.push(element)
            } else if(element.type=== 19) {
              this.faces.push(element)
            }
          })


        this.h= solidInfo[0].params.middlePoint[1]

         if(!this.threeId) {
           this.threeId= await this.createBasicPlane1(8,solidInfo[0].params.startPoint[2]*-1,'three')
           // this.threeD= (this.solidInfo.elements[0].params.startPoint[2]*-1).toFixed(2)
           this.basicD1= Math.abs(solidInfo[0].params.startPoint[2])
         }
       if(!this.fourId) {
         this.fourId= await this.createBasicPlane1(8,solidInfo[0].params.startPoint[2],'four')
         // this.fourD= this.solidInfo.elements[0].params.startPoint[2].toFixed(2)
       }
     },

      async createBasicPlane1(planeId, len, name) {
        // this.crownCADPlugin.command.clearCommand();
        // this.crownCADPlugin.command.datum.createPlaneByDistance({
        //   planeId: planeId,
        //   invertNormal: 0, paralDis: Math.abs(len), reverse: len> 0? 0: 1
        // },name);
        // await this.crownCADPlugin.command.execute();
        let params = {
          planeId:planeId,
          invertNormal: 0,
          reverse: len> 0? 0: 1,
          paralDis:Math.abs(len)
        };
        let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, name);
        return await this.getBasciPlaneId(name)
      },

      subscribeElementPick () {
        this.crownCADPlugin.request.subscribeEvent(PluginEventType.ELEMENTPICK, res => {

          if(res.element.length) {

            if(this.radio==='1') {
              if(!this.lines1.length) {
                this.lines1.push(res.element[0])
                this.addHeight()
              } else if(this.lines1[this.lines1.length- 1].id!==res.element[0].id) {
                this.lines1.push(res.element[0])
                this.addHeight()
              }
            } else if(this.radio==='2') {
              if(!this.lines2.length) {
                this.lines2.push(res.element[0])
                this.addHeight()
              } else if(this.lines2[this.lines2.length- 1].id!==res.element[0].id) {
                this.lines2.push(res.element[0])
                this.addHeight()
              }
            } else if(this.radio==='3') {
              if(!this.lines3.length) {
                this.lines3.push(res.element[0])
              } else if(this.lines3[this.lines3.length- 1].id!==res.element[0].id) {
                this.lines3.push(res.element[0])
              }
            } else if(this.radio==='4') {
              if(!this.lines4.length) {
                this.lines4.push(res.element[0])
                this.addHeight()
              } else if(this.lines4[this.lines4.length- 1].id!==res.element[0].id) {
                this.lines4.push(res.element[0])
                this.addHeight()
              }
            }

            // if(!this.oneSide) {
            //   this.oneSide= res.element[0]
            //   this.createBasicPlane(this.oneSide.param, this.oneName)
            // } else if(!this.twoSide && res.element[0].id!== this.oneSide.id){
            //     this.twoSide= res.element[0]
            //     this.createBasicPlane(this.twoSide.param, this.twoName)
            // } else if(!this.threeSide && res.element[0].id!== this.oneSide.id && res.element[0].id!== this.twoSide.id){
            //     this.threeSide= res.element[0]
            //     this.createBasicPlane(this.threeSide.param, this.threeName)
            // } else if(!this.fourSide && res.element[0].id!== this.oneSide.id && res.element[0].id!== this.twoSide.id && res.element[0].id!== this.threeSide.id){
            //     this.fourSide= res.element[0]
            //     this.createBasicPlane(this.fourSide.param, this.fourName)
            // } else if(!this.basicPlane && res.element[0].id!== this.oneSide.id && res.element[0].id!== this.twoSide.id && res.element[0].id!== this.threeSide.id && res.element[0].id!== this.fourSide.id){
            //     this.basicPlane= res.element[0]
            //     // this.createBasicPlane(this.basicPlane.param, this.oneName)
            // }
          }

        })
      },

      async createBasicPlane(param, name) {
        let temp = this.calcDist(param)

        // 根据齿形绘制不同的齿形
        switch (name) {
          case this.oneName:
            this.oneD= temp[1]
            this.oneId= temp[0]
            break;
          case this.twoName:
            //绘制矩形齿形
            this.twoD= temp[1]
            this.twoId= temp[0]
            break;
          case this.threeName:
            //绘制锯齿形
            this.threeD= temp[1]
            this.threeId= temp[0]
            break;
          case this.fourName:
            //绘制梯形齿形
            this.fourD= temp[1]
            this.fourId= temp[0]
            break;
          default:
            break;
        }
        // this.crownCADPlugin.command.clearCommand();
        // this.crownCADPlugin.command.datum.createPlaneByDistance({
        //   planeId: temp[0],
        //   invertNormal: 0, paralDis: Math.abs(temp[1]), reverse: temp[1]> 0? 0: 1
        // },name);
        // await this.crownCADPlugin.command.execute();
        let params = {
          planeId:temp[0],
          invertNormal: 0,
          reverse: temp[1]> 0? 0: 1,
          paralDis:Math.abs(temp[1])
        };
        let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, name);
        await this.getBasciPlaneId(name)
      },

      calcDist(param) {

        if(param.startPoint[0].toFixed(6) ===  param.endPoint[0].toFixed(6) && param.startPoint[1].toFixed(6) ===  param.endPoint[1].toFixed(6)) {
          return [22,param.startPoint[0]]
        } else if(param.startPoint[0].toFixed(6) ===  param.endPoint[0].toFixed(6) && param.startPoint[2].toFixed(6) ===  param.endPoint[2].toFixed(6)) {
          return [36,param.startPoint[1]]
        } else if(param.startPoint[1].toFixed(6) ===  param.endPoint[1].toFixed(6) && param.startPoint[2].toFixed(6) ===  param.endPoint[2].toFixed(6)) {
          return [8,param.startPoint[2]]
        }
      },

      async getBasciPlaneId(name) {
        this.crownCADPlugin.command.clearCommand();
        // 获取草图1的featuresid
        let res= await this.crownCADPlugin.query.getFeaturesByNames([name])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: [name]})
        // 获取草图1的entityid
        let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id])
        // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.features[0]?.id]})
        // 拉伸草图1的圆

        // switch (name) {
        //   case 'one':
        //     this.oneId= res1.entities[0].id
        //     break;
        //   case 'two':
        //     //绘制矩形齿形
        //     this.twoId= res1.entities[0].id
        //     break;
        //   case 'three':
        //     //绘制锯齿形
        //     this.threeId= res1.entities[0].id
        //     break;
        //   case 'four':
        //     //绘制梯形齿形
        //     this.fourId= res1.entities[0].id
        //     break;
        //   default:
        //     break;
        // }

        return res1.data.entities[0].id
      },

      async createPlaneSurface(id, name) {
        this.crownCADPlugin.command.surface.fillSurface({
          boundaryCurveIds: [id]
        },name)

        let res= await this.crownCADPlugin.command.execute();

        this.crownCADPlugin.command.clearCommand();
      },

      async getAll1() {
        this.crownCADPlugin.command.clearCommand();
        // 获取机翼所有实体信息
        let res = await this.crownCADPlugin.query.getEntities()

        res.data.entities.forEach(entity => {
          if(entity.type=== 5) {
            this.surfaces.push(entity)
          }else if(entity.type=== 19) {

          }
        })

      },

      async getAll2() {
        this.crownCADPlugin.command.clearCommand();
        // 获取机翼所有实体信息
        let temp= null
        let ss= []
        let res = await this.crownCADPlugin.query.getEntities()

        res.data.entities.forEach(entity => {
          if(entity.name=== '裁剪曲面') {
            temp= entity
          }
        })

        let temp1 = await this.crownCADPlugin.query.getElementsByEntityId(temp.id);


        temp1.data.elements.forEach(ele=>{
          if(ele.type=== 20) {
            ss.push(ele)
          }
        })

      },

      async trimSurfaces(limitIds,surfaceIds,keepMode,keepTags,oldSurfaceIds,newSurfaceIds,name ) {
        this.crownCADPlugin.command.clearCommand();
        this.crownCADPlugin.command.surface.trimSurface({
          limitIds: limitIds,
          surfaceIds: surfaceIds,
          keepMode: keepMode,
          keepTags:keepTags,
          oldSurfaceIds: oldSurfaceIds,
          newSurfaceIds: newSurfaceIds,
        }, name)

       await this.crownCADPlugin.command.execute();
       this.crownCADPlugin.command.clearCommand();
      },

      removeOne() {
        this.oneSide= null
      },
      removeTwo() {
        this.twoSide= null
      },
      removeThree() {
        this.threeSide= null
      },
      removeFour() {
        this.fourSide= null
      },
      removePlane() {
        this.basicPlane= null
      },
      async changeDirectionOne(){
        if(this.oneId) {

         //  this.crownCADPlugin.command.clearCommand();
         //  this.crownCADPlugin.command.datum.createPlaneByDistance({
         //    planeId: this.oneId,
         //    invertNormal: 0, paralDis: Math.abs(this.oneD), reverse:this.oneD> 0? 0: 1
         //  },'one'+ this.oneD);
         //  this.oneName= 'one'+ this.oneD
         // await this.crownCADPlugin.command.execute();
          let params = {
            planeId:this.oneId,
            invertNormal: 0,
            paralDis:Math.abs(this.oneD),
            reverse:this.oneD> 0? 0: 1
          };
          let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, 'one'+ this.oneD);
          this.oneName= 'one'+ this.oneD
        }
      },
      async changeDirectionTwo(){
        if(this.twoId) {

          // this.crownCADPlugin.command.clearCommand();
          // this.crownCADPlugin.command.datum.createPlaneByDistance({
          //   planeId: this.twoId,
          //   invertNormal: 0, paralDis: Math.abs(this.twoD), reverse:this.twoD> 0? 0: 1
          // },'two'+ this.twoD);
          // this.twoName= 'two'+ this.twoD
          // await this.crownCADPlugin.command.execute();

          let params = {
            planeId:this.twoId,
            invertNormal: 0,
            paralDis:Math.abs(this.twoD),
            reverse:this.twoD> 0? 0: 1
          };
          let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, 'two'+ this.twoD);
          this.twoName= 'two'+ this.twoD
        }
      },
      async changeDirectionThree(){
        if(this.threeId) {

          // this.crownCADPlugin.command.clearCommand();
          // this.crownCADPlugin.command.datum.createPlaneByDistance({
          //   planeId: this.threeId,
          //   invertNormal: 0, paralDis: Math.abs(this.threeD), reverse:this.threeD> 0? 0: 1
          // },'three'+ this.threeD);
          // this.threeName= 'three'+ this.threeD
          // await this.crownCADPlugin.command.execute();

          let params = {
            planeId:this.threeId,
            invertNormal: 0,
            paralDis:Math.abs(this.threeD),
            reverse:this.threeD> 0? 0: 1
          };
          let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, 'three'+ this.threeD);
          this.threeName= 'three'+ this.threeD
        }
      },
      async changeDirectionFour(){
        if(this.fourId) {

          // this.crownCADPlugin.command.clearCommand();
          // this.crownCADPlugin.command.datum.createPlaneByDistance({
          //   planeId: this.fourId,
          //   invertNormal: 0, paralDis: Math.abs(this.fourD), reverse:this.fourD> 0? 0: 1
          // },'four'+ this.fourD);
          // this.fourName= 'four'+ this.fourD
          // await this.crownCADPlugin.command.execute();

          let params = {
            planeId:this.fourId,
            invertNormal: 0,
            paralDis:Math.abs(this.fourD),
            reverse:this.fourD> 0? 0: 1
          };
          let ret = await this.crownCADPlugin.command.datum.createPlaneByDistanceIncrement(params, 'four'+ this.fourD);
          this.fourName= 'four'+ this.fourD

        }
      },

      async calSurfaces() {
        await this.trimSurfaces([this.lines1[0].id,this.lines1[1].id],[this.surfaces[0].id+1], 1,[0,0,1], [this.surfaces[0].id+1,this.surfaces[0].id+1,this.surfaces[0].id+1],[0,0,0],'裁剪曲面0')
        await this.trimSurfaces([this.lines2[0].id,this.lines2[1].id],[this.surfaces[1].id+1], 1,[0,0,1], [this.surfaces[1].id+1,this.surfaces[1].id+1,this.surfaces[1].id+1],[0,0,0],'裁剪曲面1')
        await this.trimSurfaces([this.lines3[0].id,this.lines3[1].id],[this.surfaces[2].id+1], 1,[0,1,0], [this.surfaces[2].id+1,this.surfaces[2].id+1,this.surfaces[2].id+1],[0,0,0],'裁剪曲面2')
        await this.trimSurfaces([this.lines4[0].id,this.lines4[1].id],[this.surfaces[3].id+1], 1,[0,1,0], [this.surfaces[3].id+1,this.surfaces[3].id+1,this.surfaces[3].id+1],[0,0,0],'裁剪曲面3')
      },

      async setEntityVisible(entityIds) {
        this.crownCADPlugin.command.clearCommand();
        this.crownCADPlugin.command.common.setEntityVisible({
          entityIds, visibleType: 0, })
        await this.crownCADPlugin.command.execute();
      },

      removeLine(index) {
        if(this.radio==='1') {
          this.lines1.splice(index, 1);
          this.minusHeight()
        } else if(this.radio==='2') {
          this.lines2.splice(index, 1);
          this.minusHeight()
        } else if(this.radio==='3') {
          this.lines3.splice(index, 1);
          this.minusHeight()
        } else if(this.radio==='4') {
          this.lines4.splice(index, 1);
          this.minusHeight()
        }
      }
    }
  }
</script>

<style scoped>
  >>> .el-form-item {
    margin-bottom: 0!important;
  }
  >>> .el-form-item__label {
    margin-bottom: 0!important;
  }
  >>> .el-input__suffix {
    top: 20%!important;
  }
  >>> .el-form-item {
    height: 32px!important;
  }
  >>> .el-form-item__label {
    line-height: 32px !important;
  }
  .selectItem {
    background-color: #d6eaff;
    color: #212529;
    border: 1px solid #6e7177;
    border-radius: .2rem;
    margin: .5rem .25rem;
    padding: .25rem .25rem .25rem .5rem;
    font-size: 12px;
    position: relative;
    cursor: pointer;
  }
  .color-bar {
    border-radius: 0 0 10px 0;
    height: 10px;
    left: 0;
    position: absolute;
    top: 0;
    -webkit-transition: .2s;
    transition: .2s;
    width: 10px;
  }
  .selectTitle {
    height: 24px;
    line-height: 24px;
  }
  .selectedItem {
    margin-left: 20px;
    padding: 5px 15px 5px 5px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
  }
  .selectedItem:hover {
    background-color: rgba(0,0,0,.1)/* 鼠标悬浮时的背景颜色 */
  }
</style>
